package uk.co.q3c.deplan.client.dao;

import java.util.List;

import uk.co.q3c.deplan.client.domain.DomainObject;
import uk.co.q3c.deplan.client.domain.resource.IndividualResource;
import uk.co.q3c.deplan.client.domain.resource.Resource;
import uk.co.q3c.deplan.client.domain.resource.ResourceGroup;
import uk.co.q3c.deplan.client.domain.resource.ResourcePool;
import uk.co.q3c.deplan.client.domain.task.Task;
import uk.co.q3c.deplan.server.dao.DomainDao_BigT;
import uk.co.q3c.deplan.server.service.ResourceService_BigT;

import com.googlecode.objectify.Key;
import com.google.gwt.user.client.rpc.AsyncCallback;

/**
 * Implemented by {@link ResourceService_BigT}
 * 
 * @see ResourceServiceAsync
 * @author DSowerby 19 Nov 2008
 * 
 */
public interface ResourceServiceAsync {
	/**
	 * @see ResourceService_BigT#findResourcePools()
	 */
	void findResourcePools(AsyncCallback<List<ResourcePool>> callback);

	void individualsFromKeys(List<Key<IndividualResource>> individualsKeys, AsyncCallback<List<IndividualResource>> callback);

	void groupsFromsKeys(List<Key<ResourceGroup>> groupsKeys, AsyncCallback<List<ResourceGroup>> callback);

	// the following may be repeated in each of the service interfaces, to allow
	// access to some of the un-typecast methods

	<T extends DomainObject> void keyFor(T domainObject, AsyncCallback<Key<T>> callback);

	<T extends Resource> void keyFor(T resource, AsyncCallback<Key<T>> callback);

	/**
	 * Sets the domain object's discarded flag to true and saves it. If you don't want to save it automatically, set the discarded flag
	 * directly on the domain object
	 * 
	 * @param dob
	 */
	void discard(DomainObject dob, AsyncCallback<Void> callback);

	/**
	 * <b>NOTE</b> This assumes that domainObject has no parent entity. Returns null if domainObject is null
	 * 
	 * @see DomainDao_BigT#keyFor(DomainObject)
	 * @param domainObject
	 *            the object you want the key for
	 */
	<T extends DomainObject> void getObjectFromKey(Key<T> key, AsyncCallback<T> callback);

	/**
	 * Forces a new datastore instance (@link Objectify) to be created.
	 */
	void closeSession(AsyncCallback<Void> callback);

	void save(DomainObject dob, AsyncCallback<Void> callback);

	void tasksUsingResource(IndividualResource resource, AsyncCallback<List<Task>> callback);
}